<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta name="format-detection" content="telephone=no, address=no, email=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no" />
		<meta name="HandheldFriendly" content="true" />

		<title></title>
		<link rel="stylesheet" href="../../css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
		<style>
			.red {
				color: #f00;margin-bottom:0.14rem
			}
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav mui-header">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">个人资料</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group group-form ease-out transition" id="group-form" style="margin:0px;">
				<div class="mui-input-row" style="background:none;">
					<label>电话</label>
					<input type="text" class="mui-input-clear" id="mobile" value="" disabled="true">
				</div>
				<div class="mui-input-row">
					<label>姓名</label>
					<input type="text" class="mui-input-clear" id="account" placeholder="请填写姓名">
				</div>
				<div class="mui-input-row">
					<label>公司</label>
					<input type="text" class="mui-input-clear" id="companyName" placeholder="请填写公司">
				</div>

				<div class="mui-input-row">
					<label>地址</label>
					<input type="text" class="mui-input-clear" id="address" placeholder="请填写地址">
				</div>

				<div id="message" style="color:#f00" class="none transition">
					<label>用户名或者密码错误</label>
				</div>

				<div class="mui-button-row" style="margin-top:0.5rem">
					<button type="button" class="mui-btn mui-btn-primary mui-btn-full" id="confirm" style="height:44px;background:#f1c40f;color:#fff;border-color:#f1c40f">确认</button>
				</div>

			</form>
		</div>
		<script src="../../js/resize.js"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/app.js"></script>
		<script src="../../js/ajaxFun.js"></script>
		<script>
			(function($, doc) {
				$.plusReady(function() {
					plus.nativeUI.closeWaiting();
					var userInfo = JSON.parse(localStorage.getItem('$users') || '[]')
					var confirmButton = document.getElementById("confirm");
					document.getElementById("mobile").value = userInfo.mobile;
					var groupForm = document.getElementById("group-form");

					confirmButton.addEventListener('tap', function() {
						var accountObj = document.getElementById("account");
						var companyObj = document.getElementById("companyName");
						var addressObj = document.getElementById("address");

						var account = accountObj.value.replace(/(^\s*)|(\s*$)/g, "");
						var companyName = companyObj.value.replace(/(^\s*)|(\s*$)/g, "");
						var address = addressObj.value.replace(/(^\s*)|(\s*$)/g, "");

						if(account && account.length > 10) {
							fromError('姓名不得超过10个字', accountObj, 'accounterror');
							return false;
						}else if(account && testStr(account)){
							fromError('不能包含非法字符', accountObj, 'accounterror');
							return false;
						}
						
						if(companyName && companyName.length > 30) {
							fromError('公司名称不得超过30个字', companyObj, 'companyerror');
							return false;
						}else if(companyName && testStr(companyName)){
							fromError('不能包含非法字符');
							return false;
						}
						
						if(address && address.length > 30) {
							fromError('地址不得超过30个字', addressObj, 'addresserror');
							return false;
						}else if(address && testStr(address)){
							fromError('不能包含非法字符');
							return false;
						}
						
						if(account || companyName || address){
							var url=baseUrl+'traderInfoController/editInfo.do';
							var data={
								address:address,
								companyName:companyName,
								name:account,
							};
							ajaxFun.postFun(url,data,{},function(){
								var users = JSON.parse(localStorage.getItem('$users') || '[]');
								users.nickname=account;
								app.setUser(users);							
								openWindow('index.html','main-center');
							})
						}else{
							openWindow('index.html','main-center');
						}
						
					})

					function fromError(error, obj, errorName) {
						plus.nativeUI.alert(error);
					}
				})
			}(mui, document))
		</script>
	</body>

</html>